$(function(){
    window.startDate = $('#doc').data('today');
    var getParams = getArgs();
    var currentHotel = getParams.hotel;
    if(currentHotel){
        $('#doc-header-dropdown').find('a[data-hotel|='+currentHotel+']').addClass('active');
        $('#filterSearch').attr('href','/pushWarn.html?hotel='+currentHotel+'&keys=');
    }else{
        $('#doc-header-dropdown').find('a[data-hotel|=0]').addClass('active');
    }
    var warnContent = $('#warn_content');
    warnContent.on('click','.been-read',function(e){
        e.stopPropagation();
        var submitBtn = $(this).closest('.message_list');
        var alarmClockId = submitBtn.data('alarmclockid');
        var currentHotel = submitBtn.data('hotel');
        if(submitBtn.hasClass('xiaoxi_color')){
            ajaxRequest('/Home/Hotel/saveRemind', {
                "hotel": currentHotel,
                "alarmClockId":alarmClockId,
                "isRead":1
            }, 'post', function(data) {
                submitBtn.removeClass('xiaoxi_color');
                submitBtn.find('.been-read').removeClass('been-read').addClass('hidden');
            }, function(error) { 
            });              
        }
    });
//  warnContent.on('mouseenter','.message_list',function(e){
//      e.stopPropagation();
//      var submitBtn = $(this);
//      submitBtn.find('.btn-close').removeClass('hidden'); 
//  }).on('mouseleave','.message_list',function(e){
//      e.stopPropagation();  
//      warnContent.find('.btn-close').addClass('hidden');
//  });
    warnContent.on('click','.btn-close',function(e){
        //删除推送消息
        e.stopPropagation();  
        var submitBtn = $(this);
        var remove = submitBtn.closest('.message_list');
        var alarmClockId = remove.data('alarmclockid');
        var currentHotel = remove.data('hotel');
        ajaxRequest('/Home/Hotel/saveRemind', {
            "hotel": currentHotel,
            "alarmClockId":alarmClockId,
            "dropRemind":1
        }, 'post', function(data) {
            remove.remove();
        }, function(error) { 
        });  
    });
    $('#doc-header-dropdown').on('click','li>a',function(){
        var submitBtn = $(this);
        var hotel =  submitBtn.data('hotel'); 
        $('#filterSearch').attr('href','/pushWarn.html?hotel='+hotel+'&keys=');
        if(hotel == 0){
            window.location.href = '/pushWarn.html';
        }else{
            window.location.href = '/pushWarn.html?hotel='+hotel;
        }
    });
    //查询
    $('#filterName').on('blur',function(){
        var val = $(this).val();
        var origHref = $('#filterSearch').attr('href');
        $('#filterSearch').attr('href',origHref+val);
    });    
    
});
var getArgs = function getArgs() {
    var args = {};
    var query = location.search.substring(1);
    // Get query string
    var pairs = query.split("&");
    // Break at ampersand
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        // Look for "name=value"
        if (pos == -1) {
            continue;
        }
        // If not found, skip
        var argname = pairs[i].substring(0, pos); // Extract the name
        var value = pairs[i].substring(pos + 1); // Extract the value
        value = decodeURIComponent(value); // Decode it, if needed
        args[argname] = value;
        // Store as a property
    }
    return args; // Return the object
};